package blatt2;

public class BoundedBall extends MovableBall {

	private final int X = 0;
	private final int Y = 1;

	public int[] min;
	public int[] max;

	public BoundedBall(int x, int y, int r, int rec_x1, int rec_x2, int rec_y1,
			int rec_y2) {
		super(x, y, r);
		
		//init
		min = new int[2];
		max = new int[2];

		if (rec_x1 < rec_x2) {
			min[X] = rec_x1;
			max[X] = rec_x2;
		} else {
			min[X] = rec_x2;
			max[X] = rec_x1;
		}

		if (rec_y1 < rec_y2) {
			min[Y] = rec_y1;
			max[Y] = rec_y2;
		} else {
			min[Y] = rec_y2;
			max[Y] = rec_y1;
		}
	}

	public void move() {
		super.move();

		if (x() < min[X] || x() > max[X]) {
			setMotion(-xMotion(), yMotion());
		}

		if (y() < min[Y] || y() > max[Y]) {
			setMotion(xMotion(), -yMotion());
		}
	}

}
